package cn.com.jenson.common;

import cn.com.jenson.system.Code;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable;

/**
 * action操作的结果包装
 *
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public final class Result<T> {

    private Integer code;
    private String message;
    private T data;

    public Result(T data) {
        this.code = Code.SUCCESS;
        this.message = "成功";
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> suc(T data) {
        return new Result<>(data);
    }
    public static <T> Result<T> suc(String msg, T data) {
        return new Result<>(Code.SUCCESS, msg, data);
    }


    public static <T> Result<T> fil(String msg) {
        return new Result<>(Code.SYSTEM_ERR, msg);
    }

    public static <T> Result<T> fil(Integer code, String msg) {
        return new Result<>(code, msg);
    }
}